﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-06-11 17:34:51
 * 功能：接收由原生调用的消息（函数）
**************************************************************************************/

using Game.Framework;
using UnityEngine;

public class NativeMsgReceiver : MonoBehaviour
{
    private string m_Path;

    private void Awake()
    {
        EventCenter.Instance.AddEventListen(GameEventName.CHECK_NOTIFY, CheckNotify);
    }

    private void CheckNotify()
    {
        if (string.IsNullOrEmpty(m_Path))
            EventCenter.Instance.Trigger(GameEventName.ON_HANDLE_NOTIFY, m_Path);
    }

    public void ShowMaxRewardAd(string data)
    {
        LogManager.Log($"由原生调度播放Max激励广告", "广告");
        AdMgr.Instance.ShowReward(GameDataMgr.Instance.TriggerAdType);
    }

    public void ShowMaxIntAd(string data)
    {
        LogManager.Log($"由原生调度播放Max的插屏广告", "广告");
        AdMgr.Instance.ShowInt(GameDataMgr.Instance.TriggerAdType);
    }

    public void ShowSelfRewardAdSuccess(string data)
    {
        LogManager.Log($"自己的激励广告播放成功：{data}", "广告");
        // 处理发放奖励的逻辑
        EventCenter.Instance.Trigger(GameEventName.ON_SHOW_SUCCESS_AD, EAdType.RewardedVideo, GameDataMgr.Instance.TriggerAdType);
        EventCenter.Instance.Trigger(GameEventName.ON_CLOSE_AD, EAdType.RewardedVideo, GameDataMgr.Instance.TriggerAdType);
        GameDataMgr.Instance.TriggerAdType = ETriggerAdType.None;
    }

    public void ShowSelfRewardAdFailed(string data)
    {
        LogManager.LogWarning($"自己的激励广告播放失败：{data}", "广告");
        UIUtility.ShowToast(BaseDataMgr.Instance.GetLanguageValue("The advertisement failed to play!"));
        EventCenter.Instance.Trigger(GameEventName.ON_SHOW_FAILED_AD, EAdType.RewardedVideo, GameDataMgr.Instance.TriggerAdType);
        GameDataMgr.Instance.TriggerAdType = ETriggerAdType.None;
    }

    public void ShowSelfIntAdSuccess(string data)
    {
        LogManager.Log($"自己的插屏广告播放成功：{data}", "广告");
        // 处理发放奖励的逻辑
        EventCenter.Instance.Trigger(GameEventName.ON_SHOW_SUCCESS_AD, EAdType.Interstitial, GameDataMgr.Instance.TriggerAdType);
        EventCenter.Instance.Trigger(GameEventName.ON_CLOSE_AD, EAdType.Interstitial, GameDataMgr.Instance.TriggerAdType);
        GameDataMgr.Instance.TriggerAdType = ETriggerAdType.None;
    }

    public void JumpToPath(string path)
    {
        m_Path = path;
        // 等待基础数据完成
        if (FrameworkManager.Instance.CustomProgress >= 1)
            EventCenter.Instance.Trigger(GameEventName.ON_HANDLE_NOTIFY, m_Path);
    }

    public void SaveAssetToAlbumCallback(string data)
    {
        UIUtility.ShowToast(BaseDataMgr.Instance.GetLanguageValue(data));
    }
}